<!DOCTYPE HTML>
<html lang="en">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Egg React SSR, Egg React CSR, Egg React Server Side Render, Egg React Client Side Render,Egg React SSR/CSR 工程方案-快速开始, egg,egg react ssr,egg react server side render, ant ssr,前端工程化, node, egg, webpack, easywebpack, ves, res, ssr, react server side render, vue server side render">
    <meta name="description" content="Egg React SSR/CSR 工程方案,基于 Egg + React + Webpack 服务端渲染开发指南1. 项目初始化1.1 通过 easywebpack-cli 脚手架初始化安装脚手架 npm install easywebpack-cli -g 命令行，然后就可以使用  easy 命令命令行运行 easy init选择 e...">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Egg React SSR/CSR 工程方案-快速开始 | easy-team</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper head-container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">easy-team</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>Home</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/res" class="waves-effect waves-light">
      
      <i class="fas fa-forward" style="zoom: 0.6;"></i>
      
      <span>Res</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/ves" class="waves-effect waves-light">
      
      <i class="fas fa-forward" style="zoom: 0.6;"></i>
      
      <span>Ves</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-list" style="zoom: 0.6;"></i>
      
      <span>Egg</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/egg-react">
          
          <i class="fas fa-forward" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>Egg+React</span>
        </a>
      </li>
      
      <li>
        <a href="/egg-vue">
          
          <i class="fas fa-forward" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>Egg+Vue</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/easywebpack" class="waves-effect waves-light">
      
      <i class="fas fa-building" style="zoom: 0.6;"></i>
      
      <span>Webpack</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog" class="waves-effect waves-light">
      
      <i class="fas fa-hacker-news" style="zoom: 0.6;"></i>
      
      <span>Blog</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>About</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>Contact</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="Search" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">easy-team</div>
        <div class="logo-desc">
            
            Node, 前端工程化, 多端技术
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			Home
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/res" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-forward"></i>
			
			Res
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/ves" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-forward"></i>
			
			Ves
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-list"></i>
			
			Egg
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>   
				
                  <a href="/egg-react " style="margin-left:75px";>
				  
				   <i class="fa fas fa-forward" style="position: absolute;left:50px" ></i>
			      
		          <span>Egg+React</span>
                  </a>
                </li>
              
                <li>   
				
                  <a href="/egg-vue " style="margin-left:75px";>
				  
				   <i class="fa fas fa-forward" style="position: absolute;left:50px" ></i>
			      
		          <span>Egg+Vue</span>
                  </a>
                </li>
               
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/easywebpack" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-building"></i>
			
			Webpack
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-hacker-news"></i>
			
			Blog
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			About
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			Contact
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/easy-team" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/easy-team" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    <div class="bg-cover pd-header" style="height: 9vh">
    <div class="container"></div>
</div>


    <script>
        // 每天切换 banner 图.  Switch banner image every day.
        $('.bg-cover').css('background-image', 'url(/medias/banner/' + new Date().getDay() + '.jpg)');
    </script>
    

<div class="doc-content">
    
     <div class="doc-left-nav" style="width:">
        <div class="side-nav docsidenav" style="width:">
    <div class="doc-left-nav-title">egg-react</div>
    <ul class="menu-list mobile-menu-list">
        
            
                <li class="m-nav-item m-nav-show">
                    <a href="javascript:;">
                        <i class="fas fa-fw fa-link"></i>
                        开发指南
                        <span class="m-icon"><i class="fas fa-chevron-right"></i></span>
                    </a>
                    <ul  style="display:block; background:  ;" >
                        
                            <li>   
                                <a id="m-nav-item-egg-react-init" href="/egg-react/init " 
                                    style="padding-left:75px";>
                                
                                <span>快速开始</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-start" href="/egg-react/start " 
                                    style="padding-left:75px";>
                                
                                <span>从零开始</span>
                                </a>
                            </li>
                         
                    </ul>
                </li>
            
        
            
                <li class="m-nav-item m-nav-show">
                    <a href="javascript:;">
                        <i class="fas fa-fw fa-link"></i>
                        渲染模式
                        <span class="m-icon"><i class="fas fa-chevron-right"></i></span>
                    </a>
                    <ul  style="display:block; background:  ;" >
                        
                            <li>   
                                <a id="m-nav-item-egg-react-node" href="/egg-react/node " 
                                    style="padding-left:75px";>
                                
                                <span>服务端渲染模式</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-web" href="/egg-react/web " 
                                    style="padding-left:75px";>
                                
                                <span>前端渲染模式</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-asset" href="/egg-react/asset " 
                                    style="padding-left:75px";>
                                
                                <span>asset 前端渲染</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-html" href="/egg-react/html " 
                                    style="padding-left:75px";>
                                
                                <span>HTML前端渲染</span>
                                </a>
                            </li>
                         
                    </ul>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-react/config" class="waves-effect waves-light" id="m-nav-item-egg-react-config">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        配置说明
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-react/build" class="waves-effect waves-light" id="m-nav-item-egg-react-build">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        构建流程
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-react/online" class="waves-effect waves-light" id="m-nav-item-egg-react-online">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        部署流程
                    </a>
                </li>
            
        
            
                <li class="m-nav-item m-nav-show">
                    <a href="javascript:;">
                        <i class="fas fa-fw fa-link"></i>
                        特性支持
                        <span class="m-icon"><i class="fas fa-chevron-right"></i></span>
                    </a>
                    <ul  style="display:block; background:  ;" >
                        
                            <li>   
                                <a id="m-nav-item-egg-react-seo" href="/egg-react/seo " 
                                    style="padding-left:75px";>
                                
                                <span>SEO 实现</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-antd" href="/egg-react/antd " 
                                    style="padding-left:75px";>
                                
                                <span>AntD 配置</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-babel" href="/egg-react/babel " 
                                    style="padding-left:75px";>
                                
                                <span>Babel 配置</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-typescript" href="/egg-react/typescript " 
                                    style="padding-left:75px";>
                                
                                <span>TypeScript</span>
                                </a>
                            </li>
                        
                            <li>   
                                <a id="m-nav-item-egg-react-async" href="/egg-react/async " 
                                    style="padding-left:75px";>
                                
                                <span>组件异步加载</span>
                                </a>
                            </li>
                         
                    </ul>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-react/update" class="waves-effect waves-light" id="m-nav-item-egg-react-update">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        升级更新
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-react/about" class="waves-effect waves-light" id="m-nav-item-egg-react-about">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        常见问题
                    </a>
                </li>
            
        
            
                <li class="m-nav-item">
                    <a href="/egg-react/demo" class="waves-effect waves-light" id="m-nav-item-egg-react-demo">
                        
                        <i class="fas fa-fw fa-link"></i>
                        
                        社区作品
                    </a>
                </li>
            
        
        <li><div class="divider"></div></li>
        
        <li>
            <a href="" class="waves-effect waves-light" target="_blank">
                <i class="fas fa-fw fa-link"></i>语雀文档
            </a>
        </li>
        <li>
            <a href="https://github.com/easy-team/egg-react-webpack-boilerplate" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Github
            </a>
        </li>
    </ul>
</div>

     </div>
    
    <div class="doc-right-nav">
        <div class="card" class="doc-right-card">
            <div class="card-content article-info">
                <h1 style="margin-top: 12px; text-align: center;">快速开始</h1>
                
                <div class="post-info">
                    <div class="post-date info-break-policy">
                        <i class="far fa-calendar-minus fa-fw"></i>Date:&nbsp;&nbsp;
                        2019-11-02
                    </div>
    
                    
                        
                        <div class="info-break-policy">
                            <i class="far fa-file-word fa-fw"></i>Word Count:&nbsp;&nbsp;
                            1.5k
                        </div>
                        
    
                        
                        <div class="info-break-policy">
                            <i class="far fa-clock fa-fw"></i>Read Times:&nbsp;&nbsp;
                            6 Min
                        </div>
                        
                    
                    
                    
                        <div id="busuanzi_container_page_pv" class="info-break-policy">
                            <i class="far fa-eye fa-fw"></i>Read Count:&nbsp;&nbsp;
                            <span id="busuanzi_value_page_pv"></span>
                        </div>
                    
                </div>
            </div>
            <hr class="clearfix" style="margin: 0px 0px;">
            <div class="card-content article-card-content" style="padding-top: 0px;">
                <div id="articleContent">
                    <h2 id="基于-Egg-React-Webpack-服务端渲染开发指南"><a href="#基于-Egg-React-Webpack-服务端渲染开发指南" class="headerlink" title="基于 Egg + React + Webpack 服务端渲染开发指南"></a>基于 Egg + React + Webpack 服务端渲染开发指南</h2><h2 id="1-项目初始化"><a href="#1-项目初始化" class="headerlink" title="1. 项目初始化"></a>1. 项目初始化</h2><h3 id="1-1-通过-easywebpack-cli-脚手架初始化"><a href="#1-1-通过-easywebpack-cli-脚手架初始化" class="headerlink" title="1.1 通过 easywebpack-cli 脚手架初始化"></a>1.1 通过 <a href="https://github.com/easy-team/easywebpack-cli" target="_blank" rel="noopener">easywebpack-cli</a> 脚手架初始化</h3><ol>
<li><p>安装脚手架 <code>npm install easywebpack-cli -g</code> 命令行，然后就可以使用  <code>easy</code> 命令</p>
</li>
<li><p>命令行运行 <code>easy init</code></p>
</li>
<li><p>选择 egg + react server side render boilerplate 初始化骨架项目</p>
</li>
<li><p>安装依赖 <code>npm install</code></p>
</li>
</ol>
<h3 id="1-2-通过骨架项目初始化"><a href="#1-2-通过骨架项目初始化" class="headerlink" title="1.2 通过骨架项目初始化"></a>1.2 通过骨架项目初始化</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">git</span> clone https://github.com/easy-team/egg-react-webpack-boilerplate.git
<span class="token function">npm</span> <span class="token function">install</span></code></pre>
<p>初始化的项目提供多页面和SPA(react-router/react-redux)服务端渲染实例，可以直接运行。</p>
<h3 id="1-3-vscode-插件初始化项目"><a href="#1-3-vscode-插件初始化项目" class="headerlink" title="1.3 vscode 插件初始化项目"></a>1.3 vscode 插件初始化项目</h3><p><a href="https://marketplace.visualstudio.com/items?itemName=hubcarl.vscode-easy-plugin#overview" target="_blank" rel="noopener">https://marketplace.visualstudio.com/items?itemName=hubcarl.vscode-easy-plugin#overview</a><br /></p>
<h2 id="2-项目运行"><a href="#2-项目运行" class="headerlink" title="2. 项目运行"></a>2. 项目运行</h2><h3 id="2-1-本地运行"><a href="#2-1-本地运行" class="headerlink" title="2.1 本地运行"></a>2.1 本地运行</h3><pre><code>npm run dev</code></pre><p>npm run dev 做了如下三件事情</p>
<ul>
<li><p>启动 egg 应用</p>
</li>
<li><p>启动 Webpack 构建, 文件不落地磁盘，Webpack 构建的文件都在内存里面</p>
</li>
<li><p>构建会同时启动两个 Webpack 构建服务, 客户端js构建端口9000, 服务端端口9001</p>
</li>
<li><p>构建完成，Egg 应用正式可用，自动打开浏览器</p>
</li>
</ul>
<h3 id="2-2-发布模式"><a href="#2-2-发布模式" class="headerlink" title="2.2 发布模式"></a>2.2 发布模式</h3><ul>
<li>Webpack 构建文件落地磁盘</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">npm run build 或 easy build</code></pre>
<ol>
<li><p>启动 Webpack 构建，文件落地磁盘</p>
</li>
<li><p>服务端构建的文件放到 <code>app/view</code> 目录</p>
</li>
<li><p>客户端构建的文件放到 <code>public</code> 目录</p>
</li>
<li><p>生成的 <code>manifest.json</code> 放到 <code>config</code> 目录</p>
</li>
<li><p>构建的文件都是 <code>gitignore</code>的，部署时请注意把这些文件打包进去</p>
</li>
</ol>
<ul>
<li>运行</li>
</ul>
<p>启动应用前， 请设置 <code>EGG_SERVER_ENV</code> 环境变量，测试环境设置 <code>test</code>， 正式环境设置 <code>prod</code></p>
<pre><code>npm start</code></pre><h2 id="3-项目构建"><a href="#3-项目构建" class="headerlink" title="3. 项目构建"></a>3. 项目构建</h2><ul>
<li><p>通过项目根目录下的 <code>webpack.config.js</code> 配置文件构造出 Webpack 实际的配置文件</p>
</li>
<li><p>通过 <a href="https://github.com/easy-webpack/egg-webpack" target="_blank" rel="noopener">egg-webpack</a> 插件提供本地开发构建和热更新支持。SSR 模式时，egg-webpack 会启动两个 Webpack 构建服务, 客户端jsbundle构建，端口9000, 服务端jsbundle构建端口9001。</p>
</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript"><span class="token comment" spellcheck="true">// config/config.local.js 本地 npm start 使用</span>
<span class="token keyword">const</span> easywebpack <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'easywebpack-react'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
exports<span class="token punctuation">.</span>webpack <span class="token operator">=</span> <span class="token punctuation">{</span>
  webpackConfigList<span class="token punctuation">:</span>easywebpack<span class="token punctuation">.</span><span class="token function">getWebpackConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>webpack.config.js  配置</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript"><span class="token comment" spellcheck="true">// ${root}/webpack.config.js</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  entry<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    home<span class="token punctuation">:</span> <span class="token string">'app/web/page/home/index.jsx'</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<h2 id="4-项目规范"><a href="#4-项目规范" class="headerlink" title="4. 项目规范"></a>4. 项目规范</h2><ul>
<li><p><a href="https://eggjs.org/zh-cn/basics/structure.html" target="_blank" rel="noopener">遵循 egg 开发规范</a></p>
</li>
<li><p>React 项目代码放到 app/web 目录，页面入口目录为 page，该目录的 所有 .jsx 文件默认会作为 Webpack 的 entry 构建入口。建议每个页面目录的只保留一个.jsx 文件，jsx关联的组件可以放到widget 或者 component 目录。</p>
</li>
</ul>
<h2 id="5-项目开发"><a href="#5-项目开发" class="headerlink" title="5. 项目开发"></a>5. 项目开发</h2><p>支持多页面/单页面服务端渲染, 前端渲染, 静态页面三种方式.</p>
<h3 id="5-1-多页面服务端渲染实现"><a href="#5-1-多页面服务端渲染实现" class="headerlink" title="5.1 多页面服务端渲染实现"></a>5.1 多页面服务端渲染实现</h3><h4 id="5-1-1-多页面前端页面实现"><a href="#5-1-1-多页面前端页面实现" class="headerlink" title="5.1.1 多页面前端页面实现"></a>5.1.1 多页面前端页面实现</h4><p>在app/web/page 目录下面创建 home 目录 和 home.jsx 文件, Webpack 自动根据 .jsx 文件创建 entry入口, 具体实现请见<a href="https://easy-team.github.io/easywebpack/config">webpack.config.js</a></p>
<ul>
<li>home.jsx 以组件的方式实现页面逻辑</li>
</ul>
<pre class=" language-jsx"><code class="language-jsx"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> Header <span class="token keyword">from</span> <span class="token string">'component/layout/standard/header/header.jsx'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> List <span class="token keyword">from</span> <span class="token string">'component/home/list.jsx'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token string">'./home.css'</span><span class="token punctuation">;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">class</span> <span class="token class-name">Home</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token function">componentDidMount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'----componentDidMount-----'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Header</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Header</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>main<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>page-container</span> <span class="token attr-name">page-component"</span><span class="token punctuation">></span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>List</span> <span class="token attr-name">list</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>list<span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>List</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span></code></pre>
<h4 id="5-1-2-通过-egg-view-react-ssr-插件-render-方法实现-Server-Side-Render"><a href="#5-1-2-通过-egg-view-react-ssr-插件-render-方法实现-Server-Side-Render" class="headerlink" title="5.1.2 通过 egg-view-react-ssr 插件 render 方法实现 Server Side Render"></a>5.1.2 通过 <code>egg-view-react-ssr</code> 插件 <code>render</code> 方法实现 Server Side Render</h4><ul>
<li>创建 controller 文件 home.js</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">exports<span class="token punctuation">.</span>index <span class="token operator">=</span> <span class="token keyword">function</span><span class="token operator">*</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">yield</span> ctx<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token string">'home/home.js'</span><span class="token punctuation">,</span> Model<span class="token punctuation">.</span><span class="token function">getPage</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>添加路由配置</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">app<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">'/home'</span><span class="token punctuation">,</span> app<span class="token punctuation">.</span>controller<span class="token punctuation">.</span>home<span class="token punctuation">.</span>home<span class="token punctuation">.</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="5-1-3-通过-egg-view-react-ssr-插件-renderClient-方法实现-Client-Side-Render"><a href="#5-1-3-通过-egg-view-react-ssr-插件-renderClient-方法实现-Client-Side-Render" class="headerlink" title="5.1.3  通过 egg-view-react-ssr 插件 renderClient 方法实现 Client Side Render"></a>5.1.3  通过 <code>egg-view-react-ssr</code> 插件 <code>renderClient</code> 方法实现 Client Side Render</h4><ul>
<li>在 controller 文件home.js 添加 client 方法</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">exports<span class="token punctuation">.</span>client <span class="token operator">=</span> <span class="token keyword">function</span><span class="token operator">*</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">yield</span> ctx<span class="token punctuation">.</span><span class="token function">renderClient</span><span class="token punctuation">(</span><span class="token string">'home/home.js'</span><span class="token punctuation">,</span> Model<span class="token punctuation">.</span><span class="token function">getPage</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>添加路由配置</li>
</ul>
<pre class=" language-javascript"><code class="language-javascript">app<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">'/client'</span><span class="token punctuation">,</span> app<span class="token punctuation">.</span>controller<span class="token punctuation">.</span>home<span class="token punctuation">.</span>home<span class="token punctuation">.</span>client<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h2 id="6-项目部署"><a href="#6-项目部署" class="headerlink" title="6. 项目部署"></a>6. 项目部署</h2><ul>
<li><p>正式环境部署，请设置 <code>EGG_SERVER_ENV=prod</code> 环境变量, 更多请见<a href="https://eggjs.org/zh-cn/basics/env.html" target="_blank" rel="noopener">运行环境</a></p>
</li>
<li><p>构建的 <code>app/view</code> 目录, <code>public</code> 目录以及 <code>buildConfig.json</code> 和 <code>manifest.json</code>等文件, 都是 <code>gitignore</code> 的，部署时请注意把这些文件打包进去。</p>
</li>
</ul>
<h3 id="一-Webpack构建目录"><a href="#一-Webpack构建目录" class="headerlink" title="一. Webpack构建目录"></a>一. Webpack构建目录</h3><ul>
<li><p>Webpack构建服务端(Node) JSBundle运行文件, 构建的服务端渲染模板文件位置 <code>${app_root}/app/view</code></p>
</li>
<li><p>Webpack构建浏览器JSBundle运行文件, 构建的前端资源(js/css/image)文件位置 <code>${app_root}/public</code></p>
</li>
<li><p>Webpack构建的 <code>manifest.json</code> 和 <code>buildConfig.js</code> 文件位置 <code>${app_root}/config</code> 目录</p>
</li>
<li><p>easywebpack-cli 构建配置文件 <code>webpack.config.js</code> 放到项目根目录<code>${app_root}/webpack.config.js</code></p>
</li>
<li><p>React代码文件<code>${app_root}/app/web</code> 下面, 主要包括 <code>asset</code>, <code>component</code>, <code>framework</code>, <code>page</code>, <code>store</code>, <code>view</code> 等目录</p>
</li>
</ul>
<pre class=" language-html"><code class="language-html">├── asset                    // 资源文件
    │   ├── css 
    │   │   ├── global.css
    │   │   ├── normalize.css
    │   │   └── style.css
    │   ├── images
    │   │   ├── favicon.ico
    │   │   ├── loading.gif
    │   │   └── logo.png
    ├── component                // jsx组件
    │   ├── home
    │   │   └── list.jsx
    │   └── layout
    │       └── standard
    │           └── header
    │               ├── header.css
    │               └── header.jsx
    ├── framework
    │   └── entry
    │       ├── app.js
    │       └── loader.js
    ├── page               // 页面目录, jsx结尾的的文件默认作为entry入口
    │   ├── hello
    │   │   └── hello.jsx  // 页面入口文件, 根据framework/entry/loader.js模板自动构建
    │   └── home
    │       ├── home.css
    │       └── home.jsx
    └── view
        └── layout.jsx     // layout模板文件, 提供统一html, header, body结构, page下面的jsx文件无需关心</code></pre>
<h3 id="二-项目结构和基本规范"><a href="#二-项目结构和基本规范" class="headerlink" title="二. 项目结构和基本规范"></a>二. 项目结构和基本规范</h3><pre class=" language-html"><code class="language-html">├── app
│   ├── controller
│   │   ├── test
│   │   │   └── test.js
│   ├── extend
│   ├── lib
│   ├── middleware
│   ├── mocks
│   ├── proxy
│   ├── router.js
│   ├── view
│   │   ├── home
│   │   │     └── home.js                 // 服务器编译的jsbundle文件
│   └── web                               // 前端工程目录
│       ├── asset                         // 存放公共js,css资源
│       ├── framework                     // 前端公共库和第三方库
│       │   └── entry                          
│       │       ├── loader.js              // 根据jsx文件自动生成entry入口文件loader
│       ├── page                           // 前端页面和webpack构建目录, 也就是webpack打包配置entryDir
│       │   ├── home                       // 每个页面遵循目录名, js文件名, scss文件名, jsx文件名相同
│       │   │   ├── home.scss
│       │   │   ├── index.jsx
│       └── component                         // 公共业务组件, 比如loading, toast等, 遵循目录名, js文件名, scss文件名, jsx文件名相同
│           ├── loading
│           │   ├── loading.scss
│           │   └── loading.jsx
│           ├── test
│           │   ├── test.jsx
│           │   └── test.scss
│           └── toast
│               ├── toast.scss
│               └── toast.jsx
├── config
│   ├── config.default.js
│   ├── config.local.js
│   ├── config.prod.js
│   ├── config.test.js
│   └── plugin.js
├── doc
├── index.js
├── webpack.config.js                      // easywebpack-cli 构建配置
├── public                                 // webpack编译目录结构, render文件查找目录
│   ├── static
│   │   ├── css
│   │   │   ├── home
│   │   │   │   ├── home.07012d33.css
│   │   │   └── test
│   │   │       ├── test.4bbb32ce.css
│   │   ├── img
│   │   │   ├── change_top.4735c57.png
│   │   │   └── intro.0e66266.png
│   ├── test
│   │   └── test.js
│   └── vendor.js                         // 生成的公共打包库</code></pre>
<h2 id="8-项目和插件"><a href="#8-项目和插件" class="headerlink" title="8. 项目和插件"></a>8. 项目和插件</h2><ul>
<li><p><a href="https://github.com/easy-team/egg-react-webpack-boilerplate" target="_blank" rel="noopener">egg-react-webpack-boilerplate</a>基于easywebpack-react和egg-view-react(ssr)插件的工程骨架项目</p>
</li>
<li><p><a href="https://github.com/easy-team/easywebpack-react" target="_blank" rel="noopener">easywebpack-react</a> Webpack React 构建工程化方案.</p>
</li>
<li><p><a href="https://github.com/easy-team/easywebpack-cli" target="_blank" rel="noopener">easywebpack-cli</a>  Webpack 构建工程化脚手架.</p>
</li>
<li><p><a href="https://github.com/easy-team/egg-view-vue-ssr" target="_blank" rel="noopener">egg-view-react-ssr</a> react ssr 解决方案.</p>
</li>
<li><p><a href="https://github.com/easy-team/egg-webpack" target="_blank" rel="noopener">egg-webpack</a> 本地开发热更新使用.</p>
</li>
<li><p><a href="https://github.com/easy-team/egg-webpack-react" target="_blank" rel="noopener">egg-webpack-react</a> 本地开发渲染内存读取辅助插件</p>
</li>
</ul>

                </div>
                <hr/>
    
                

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        Author:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://easy-team.github.io" rel="external nofollow noreferrer">sky</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        Link:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://easy-team.github.io/egg-react/init/">https://easy-team.github.io/egg-react/init/</a>
                </span>
            </div>
            <div class="reprint__type">
                    <span class="reprint-meta" style="font-weight: bold;">
                        <i class="fas fa-link">
                            yuque:
                        </i>
                    </span>
                    <span class="reprint-info">
                        <a href="https://yuque.com/easy-team/egg-react/init/" target="_blank" rel="noopener">https://yuque.com/easy-team/egg-react/init/</a>
                    </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        Reprint policy:
                    </i>
                </span>
                <span class="reprint-info">
                    All articles in this blog are used except for special statements
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    reprint polocy. If reproduced, please indicate source
                    <a href="https://easy-team.github.io" target="_blank">sky</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>Copied successfully, please follow the reprint policy of this article</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">more</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>


    
                <div class="tag_share" style="display: block; margin-top: 20px;">
                    <div class="post-meta__tag-list" style="display: inline-block;">
                        
                            
                        
                    </div>
                    <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                        <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                    </div>

                </div>
                
            </div>
        </div>
        
    
        
    
        
    
        
    
        
    
        

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;Previous</div>
            <div class="card">
                <a href="/egg-react/online/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/12.jpg" class="responsive-img" alt="部署流程">
                        
                        <span class="card-title">部署流程</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            开发部署新项目开发在 egg-react-webpack-boilerplate 骨架项目中, 提供了一些demo, 如果要进行新项目开发，可以删除部分文件：app/web/page 是页面目录。下面的每个目录都是一个单独的页面，其中 spa 目录是一个单页面服务端渲染例子，其他是简单的 Re...
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2019-11-02
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            sky
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                Next&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/egg-react/config/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/19.jpg" class="responsive-img" alt="配置说明">
                        
                        <span class="card-title">配置说明</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Webpack 标准配置
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2019-11-02
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            sky
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
    </div>
</article>

     </div>
</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('50')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + 'From: easy-team<br />'
            + 'Author: sky<br />'
            + 'Link: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->

<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>


<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>

    
<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>

<!-- menu-selected -->
<script>
    var pathname = location.pathname.replace(/^\//, '').replace(/\/$/, '').replace(/\//g, '-');
    $('#m-nav-item-' + pathname).addClass('doc-left-nav-mene-selected');
</script>

    <footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">年份</span>
            <a href="https://easy-team.github.io" target="_blank">sky</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/easy-team" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">106.5k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    window.setTimeout("siteTime()", 1000);
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2019";
                    var startMonth = "10";
                    var startDate = "20";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/hubcarl" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:hubcarl@126.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=433207205" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 433207205" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>



    <a href="https://weibo.com/hubcarl" class="tooltipped" target="_blank" data-tooltip="关注我的微博: https://weibo.com/hubcarl" data-position="top" data-delay="50">
        <i class="fab fa-weibo"></i>
    </a>



    <a href="https://zhuanlan.zhihu.com/easywebpack" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://zhuanlan.zhihu.com/easywebpack" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;Search</span>
            <input type="search" id="searchInput" name="s" placeholder="Please enter a search keyword"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    

    <!-- Global site tag (gtag.js) - Google Analytics -->


    <!-- Baidu Analytics -->


    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        bp.async = true;
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
